import pymysql

# 虚拟机的
# 数据库连接参数
host = '192.168.117.158'  # 数据库主机地址
user = 'remote'  # 数据库用户名
password = 'Ubtest123.'  # 数据库密码
database = 'blog'  # 数据库名称
port = 3306  # 数据库端口，默认是3306

# 创建连接
try:
    connection = pymysql.connect(
        host=host,
        user=user,
        password=password,
        database=database,
        port=port,
    )

    print("连接成功")

except pymysql.MySQLError as e:
    print(f"数据库连接失败: {e}")

finally:
  pass